package com.CRApp.utils;

import java.util.Map;

/**
 * @ClassName: ThreadLocal
 * @Author : LuoFan洛樊
 * @Date : 2025/2/6 - 16:10
 * Description : TODO
 */
/**
 * ThreadLocal 工具类
 */
@SuppressWarnings("all")
public class ThreadLocalUtil {
    // 创建ThreadLocal对象
    private static final ThreadLocal<Map<String, Object>> THREAD_LOCAL = new ThreadLocal<>();

    // 存储用户数据
    public static void set(Map<String, Object> map) {
        THREAD_LOCAL.set(map);
    }

    // 获取用户数据
    public static Map<String, Object> get() {
        return THREAD_LOCAL.get();
    }

    // 获取当前登录用户ID
    public static Integer getCurrentUser() {
        Map<String, Object> map = THREAD_LOCAL.get();
        if (map == null) {
            return null;
        }
        return (Integer) map.get("userId");
    }

    // 清除ThreadLocal中的数据
    public static void remove() {
        THREAD_LOCAL.remove();
    }
}

